package string;

import org.junit.Test;

import java.nio.charset.StandardCharsets;

/**
 * author : yeswater
 * date : 2023/7/13
 */

public class StringTest {

    /**
     * string 与 基本数据类型的转换
     */
    @Test
    public void test1() {
        int num = 10;
        String str = String.valueOf(num);
        String str2 = "" + num;

        int num2 = Integer.parseInt(str);
        System.out.println("str " + str);
        System.out.println("str2 " + str2);
        System.out.println("num2 " + num2);
    }

    /**
     * string 与 char[]转换
     */
    @Test
    public void test2() {
        String str = new String("abc中国");
        byte[] arr = str.getBytes(StandardCharsets.UTF_8);
        for (byte b : arr) {
            System.out.println(b);
        }

        String str2 = new String(arr);
        System.out.println(str2);
    }

}
